package com.dianyingyuyue.service;

import com.dianyingyuyue.entity.Plan;
import com.dianyingyuyue.entity.User;
import com.dianyingyuyue.util.JdbcUtil;

import java.util.List;

/**
 * 用户业务层
 */
public class UserService {


    /**
     * 用户登录
     * @param obj
     * @return
     */
    public User login(List<Object> obj) {
        String sql="select * from user where username=? and pwd=? and utype=? ";
        List<User> users= JdbcUtil.executeQuery(sql, obj,User.class);
        if(users!=null&&users.size()>=1){
            return users.get(0);
        }
        return null;
    }


    /**
     * 注册
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into user(username,pwd,sex,phone,utype,ctime) values(?,?,?,?,?,now()) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }

    /**
     * 修改信息
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update user set username=?,pwd=?,sex=?,phone=? where id=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


    public User getId(int id) {
        String sql="select * from user where id="+id;
        List<User> users= JdbcUtil.executeQuery(sql,null,User.class);
        return users.get(0);
    }
}
